package com.crl.map.model
{
	import flash.geom.Point;

	public class TileSystem
	{
		private var _col:int;
		private var _row:int;
		private var _ox:int;
		private var _oy:int;
		private var _tw:int;
		private var _th:int;
		
		public function TileSystem(col:int,row:int,ox:int,oy:int,tw:int,th:int)
		{
			_col=col;
			_row=row;
			
			_ox=ox;
			_oy=oy;
			
			_tw=tw;
			_th=th;
		}
		
		
		public function get th():int
		{
			return _th;
		}

		public function get tw():int
		{
			return _tw;
		}

		public function get oy():int
		{
			return _oy;
		}

		public function get ox():int
		{
			return _ox;
		}

		public function get row():int
		{
			return _row;
		}

		public function get col():int
		{
			return _col;
		}

		public function getScreenByTile(tx:int,ty:int):Point{
			var sx:int=(tx-ty)*tw/2;
			var sy:int=(tx+ty)*th/2;
			return new Point(sx+ox,sy+oy);
		}
		
		public function getTileByScreen(sx:int,sy:int):Point{
			sx=sx-ox;
			sy=sy-oy;
			
			var tx:int=Math.floor(sy/th+ sx/tw);
			var ty:int=Math.floor(sy/th - sx/tw);
			
			return new Point(tx,ty);
		}
	}
}